package org.elanfox.intellicommunity.msg.server.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.elanfox.intellicommunity.msg.dto.CmdWriteParam;
import org.elanfox.intellicommunity.msg.ienum.CmdEnums;
import org.elanfox.intellicommunity.msg.server.base.MsgCommunicationUtils;
import org.elanfox.intellicommunity.msg.server.base.WriteResult;
import org.elanfox.intellicommunity.msg.server.service.CmdControlWriter;
import org.springframework.stereotype.Service;

/**
 * @author allan
 * @version 1.0.0
 * @date 2020/3/16
 */
@Service
@Slf4j
public class CmdControlWriterImpl implements CmdControlWriter {
    @Override
    public WriteResult reboot(CmdWriteParam cmdWriteParam) {
        String hexLength = "0006";
        return MsgCommunicationUtils.request(cmdWriteParam.getHexAddr(), CmdEnums.Code.REBOOT, "", hexLength);
    }

    @Override
    public WriteResult write(CmdEnums.Code cmdCode, CmdWriteParam arg) {
        switch (cmdCode) {
            case REBOOT:
                return reboot(arg);
            default:
                log.error("method not supported for cmd code " + cmdCode.getDesc());
                return null;
        }
    }
}
